﻿//yangx 写的loading插件
(function($) {
    var loading = function(ele, opt) {
        this.$element = ele;
        this.defaults = {
            content:"<img style='margin:0 auto;top:45%;left:50%;position:fixed' src='../resources/images/loading.gif'||opt.imgPath>"
        };
        this.options = $.extend({}, this.defaults, opt);
        this.ldiv=$('<div></div>')
            .attr('id', 'loading_modal')
            .css({
                "background-color":"rgba(148, 148, 150,0.6)",
                zIndex: 3000,
                //padding: '10px',
                width: '100%',
                height: '100%',
                margin: '0 auto',
                opacity: this.options.opacity,
                position: 'absolute',
                top: '0',
                left: '0%'
            }).append(this.options.content);
    }

    loading.prototype.show=function(){

            $('body').append(this.ldiv.show()) ;


    }
    loading.prototype.close=function(){
        this.ldiv.fadeOut(800,function(){
            $(this).remove();
        });
        //setTimeout(function(){
        //     $("#loading_modal").remove() ;
        //},1600)
    }
    $.fn.loading = function(options) {
        var loadingplus=this.data("loading_plus");
        if(!loadingplus){
            loadingplus=new loading(this, options);
            this.data("loading_plus",loadingplus);
        }
        return loadingplus;
        //调用其方法
    }
})(jQuery);